package com.zzz.demo01;

import org.w3c.dom.ls.LSException;

import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.Optional;

/**
 * @author zhuzhizun
 * @date 2021/7/28
 */
public class OptionalTest {
    public static void main(String[] args) {
/*        Student student = new Student("yh",21,"123");
        Student student1 = Optional.ofNullable(student).orElse(creatStudent());
        Student student2 = Optional.ofNullable(student).orElseGet(() -> creatStudent());
        System.out.println(student1);
        System.out.println(student2);*/

        ArrayList<String> list = new ArrayList<>();
        list.add("AAA");
        list.add("BBB");
        list.add("CCC");
        ArrayList<String> resultList = new ArrayList<>();
//        System.out.println(list.hashCode());
//        Optional.ofNullable(list).ifPresent(e -> {
//            System.out.println(e.hashCode());
//            list.forEach(el -> {
//                System.out.println(el);
//                resultList.add(el+"----R");
//            });
//        });
        Optional.ofNullable(list).ifPresent(e -> list.forEach(el -> Optional.ofNullable(el).ifPresent(resultList::add)));



        resultList.forEach(System.out::println);
    }

    public static Student creatStudent(){
       return new Student("zzz",22,"13648380723");
    }
}
